export function toast(content) {
	uni.showToast({
		icon: 'none',
		title: content
	})
}
export function toastC(content) {
	uni.showToast({
		title: content
	})
}
export function toastload(title='加载中...') {
	uni.showLoading({
		title,
		forbidClick: true,
		loadingType: 'spinner',
	});
}
export function closeload() {
	uni.hideLoading()
}


export function showConfirm(content,cancel) {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title: '提示',
			showCancel:cancel,
			content: content,
			cancelText: '取消',
			confirmText: '确定',
			success: function(res) {
				resolve(res)
			}
		})
	})
}

export function copy(value) {
	//提示模板
	uni.showModal({
		content: value, //模板中提示的内容
		confirmText: '复制内容',
		success: (res) => { //点击复制内容的后调函数
			if (res.confirm) {
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功'
						})
					}
				});
			}

		}
	});
}



export function tansParams(params) {
	let result = ''
	for (const propName of Object.keys(params)) {
		const value = params[propName]
		var part = encodeURIComponent(propName) + "="
		if (value !== null && value !== "" && typeof(value) !== "undefined") {
			if (typeof value === 'object') {
				for (const key of Object.keys(value)) {
					if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
						let params = propName + '[' + key + ']'
						var subPart = encodeURIComponent(params) + "="
						result += subPart + encodeURIComponent(value[key]) + "&"
					}
				}
			} else {
				result += part + encodeURIComponent(value) + "&"
			}
		}
	}
	return result
}



export function tiao(url, params) {
	let token = uni.getStorageSync("access_token")
	if (!token) {
		uni.showModal({
			title: '提示',
			content: "你还没有登录,是否去登录",
			cancelText: '取消',
			confirmText: '确定',
			success: function(res) {
				if (res.confirm == true) {
					uni.navigateTo({
						url: '/pages/wx-login/wx-login'
					})
				}

			},

		})
		return
	}
	if (params) {
		let queryString = Object.keys(params).map(key => {
			return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
		}).join('&');

		if (url.includes('?')) {
			url += '&' + queryString;
		} else {
			url += '?' + queryString;
		}
	}
	console.log(url);
	uni.navigateTo({
		url: url
	});
}